package com.jojo.bubble.controller;

import com.jojo.bubble.entity.AuthUser;
import com.jojo.bubble.service.AuthUserService;
import com.jojo.bubble.common.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.ObjectUtils;
import com.jojo.bubble.common.enums.JsonResultEnum;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户权限(AuthUser)表控制层
 *
 * @author jojo
 * @since 2023-07-21 04:47:27
 */
@RestController
@RequestMapping("/admin/authUser")
public class AuthUserController {
    /**
     * 服务对象
     */
    @Resource
    private AuthUserService authUserService;


    @GetMapping("/list")
    public AjaxResult getList(AuthUser record) {
        List<AuthUser> authUserList = authUserService.getList(record);
        return AjaxResult.success(authUserList);
    }

    @GetMapping("/info")
    public AjaxResult getInfo(Integer id) {
        AuthUser authUser = authUserService.getInfo(id);
        return AjaxResult.success(authUser);
    }

    @PostMapping("/insert")
    public AjaxResult insert(AuthUser record) {
        authUserService.insert(record);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    public AjaxResult update(AuthUser record) {
        AuthUser authUser = authUserService.getInfo(record.getId());
        if (ObjectUtils.isEmpty(authUser)) {
            return AjaxResult.error(JsonResultEnum.RECORD_NULL);
        }
        authUserService.update(record);
        return AjaxResult.success();
    }

    @PostMapping("/delete")
    public AjaxResult delete(int id) {
        authUserService.delete(id);
        return AjaxResult.success();
    }
}

